package com.example.simplesvc;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

@Component
public class MyWebListener implements ServletContextListener {

    private static Logger log = LoggerFactory.getLogger(MyWebListener.class);


    @Override
    public void contextInitialized(ServletContextEvent sce) {
        ServletContextListener.super.contextInitialized(sce);
        log.info("------------myweblister ctx inited");
    }

    public void contextDestroyed(ServletContextEvent sce) {
        log.info("receiced event tomcat is stopping @ {}", System.currentTimeMillis());
        // 监听context destroy事件 确定服务器处于关闭状态，设置服务器推出服务状态到 ServerStateHolder
        ServerStateHolder.getInstance().setServerStopping();

        MyServerStopListenerRegister.getInstance().notifyAllListenersServerStopping();
    }
}
